/*
 * Description: 在线消息 - 聊天消息 控制器
 * Author: wangyifei
 * DateCreated: 2024-06-06 16:48
 */

import { messageHttp } from '@/utils/request';
import type { IRes, IResList, IResPageList, PagePayload } from '@/utils/request';
import type { MsgFmt, MsgType } from '../config';

// 分页查询 在线消息 - 聊天消息
export interface RecordsParam {
	groupId?: number;
	msg?: string;
	/** 0=text, 1=markdown, 2=html, 3=image, 4=voice, 5=video, 6=music, 7=file */
	msgFmt?: MsgFmt;
	/** 0=普通消息, 1=系统消息 */
	msgType?: MsgType;
	readMark?: number;
	senderId?: number;
}
export interface RecordsRes extends RecordsParam {
	id: number;
	createdTime: Date;
	senderAvatar: string;
	senderName: string;
}
export const selectRecordsPage = (data: PagePayload<RecordsParam>) =>
	messageHttp.post<IResPageList<RecordsRes>>({
		url: '/chatting-records/page',
		data
	});

// 查询列表
export const selectRecordsList = (data: RecordsParam) =>
	messageHttp.post<IResList<RecordsRes>>({
		url: '/chatting-records/list',
		data
	});

// 新增 在线消息 - 聊天消息
export interface InsertRecordParam {
	groupId?: number;
	msg?: string;
	msgFmt?: number;
	msgType?: number;
	readMark?: number;
	senderId?: number;
	senderName?: string;
}
export interface InsertRecordRes extends InsertRecordParam {
	id: number;
	senderAvatar: string;
}
export const insertRecordItem = (data: InsertRecordParam) =>
	messageHttp.post<IRes<InsertRecordRes>>({
		url: '/chatting-records/',
		data
	});

// 修改 在线消息 - 聊天消息
export interface UpdateRecordParam {
	groupId?: number;
	id?: number;
	msg?: string;
	msgFmt?: number;
	msgType?: number;
	readMark?: number;
	senderId?: number;
}
export interface UpdateRecordRes extends UpdateRecordParam {
	senderAvatar: string;
	senderName: string;
}
export const updateRecordItem = (data: UpdateRecordParam) =>
	messageHttp.put<IRes<UpdateRecordRes>>({
		url: '/chatting-records/',
		data
	});
